import path from "path";
import TerserPlugin from "terser-webpack-plugin";
import { CleanWebpackPlugin } from "clean-webpack-plugin";
import { Configuration } from "webpack";
// 工程打包的配置

const resolve = (...dirs: string[]) => path.resolve(process.cwd(), ...dirs);

const config: Configuration = {
  mode: "none",
  target: "node",
  entry: {
    main: resolve("src/main")
  },
  output: {
    filename: "[name].[hash:8].js",
    path: resolve("build")
  },
  optimization: {
    minimize: true,
    minimizer: [new TerserPlugin()]
  },
  module: {
    rules: [
      {
        test: /\.tsx?$/,
        loader: "ts-loader"
      }
    ]
  },
  plugins: [new CleanWebpackPlugin({ verbose: true })],
  resolve: {
    alias: {
      "@": resolve("src")
    },
    extensions: [".js", ".ts", ".tsx"]
  }
};

export default config;
